"use strict";
require("test").setup();

var Coroutine = require('coroutine');
var hash = require('hash');

var str_prefix = "ZG";

describe("user", function() {
    before(function() {
    });
    after(function() {
         clearDB();
    });


    it("登录", function() {
        httpPost("GET", "/v1.0/api/user/Sync", {})
        var t = "123"
        var result = httpPost("POST", "/v1.0/api/user/WebLogin", {
            "phone": "18888888888",
            "password": hash.md5(hash.md5("ZHYQ2022").digest().hex() + t).digest().hex(),
            "t": t,
        })
        assert.equal(result.code, "200");
        assert.equal(result.data.id, 2);
        assert.equal(result.data.role, "超级管理员");
        assert.equal(result.data.edited_password, true);
    });


    it("创建职工审批 ", function () {
        var result = httpPost("POST", "/v1.0/api/staffRecord/Create", {
            name :"张三明",
            gender:"男",
            phone:"15678967654",
            department:"肛肠科",
            staff_ic:"1589261",
            staff_hash:"12464657",
            record_type:"职工",
            created_by:"张老三"
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        var result1 = httpPost("POST", "/v1.0/api/staffRecord/Create", {
            name :"张三",
            gender:"女",
            phone:"15688887654",
            department:"内科",
            staff_ic:"1500261",
            staff_hash:"127864657",
            record_type:"职工",
            created_by:"张老三"
        })
        assert.equal(result1.code, "200");
        assert.equal(result1.msg, "success");
    });


    it("职工审批列表", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/List", {
        })
        console.error("职工审批列表 : ",result)
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.list.length,2);
    });

    it("职工通过审批", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/Pass", {
            id:10002,
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.id,10002);
    });


    it("职工通过审批失效", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/Invalid", {
            id:10002,
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
    });

    it("审批操作日志", function() {
        var result = httpPost("POST", "/v1.0/api/operation/List", {
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.result.length, 2);
    });

    it("工作台审批信息", function() {
        var result = httpPost("GET", "/v1.0/api/operation/ApprovalCount", {
        })
        console.error("工作台审批信息 超级管理员 : ",result)
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
    });


    xit("用户登出", function () {
        var result = httpPost("POST", "/v1.0/api/user/Logout", {})
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");

        var result1 = httpPost("POST", "/v1.0/api/user/Get", {
            "id": 2,
        })

        assert.equal(result1.code, "401");
        assert.equal(result1.msg, "用户未登录");
    });

    xit("登录", function() {
        httpPost("GET", "/v1.0/api/user/Sync", {})
        var t = "123"
        var result = httpPost("POST", "/v1.0/api/user/WebLogin", {
            "phone": "17986576723",
            "password": hash.md5(hash.md5("ZHYQ2022").digest().hex() + t).digest().hex(),
            "t": t,
        })
        assert.equal(result.code, "200");
        assert.equal(result.data.role, "管理员");
    });

    it("工作台审批信息", function() {
        var result = httpPost("GET", "/v1.0/api/operation/ApprovalCount", {
        })
        console.error("工作台审批信息 管理员: ",result)
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
    });

    //创建设备令牌
    it("创建设备令牌", function () {
        var result = httpPost("POST", "/v1.0/api/operation/TokenCreate", {
            "end_at":"2022-03-30 19:02:12",
            "ip":"192.168.1.231"
        })
        console.error("创建设备令牌" ,result)
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
    });

    //令牌列表
    it("令牌列表", function() {
        var result = httpPost("GET", "/v1.0/api/operation/TokenList", {
        })
        console.error("令牌列表 : ",result)
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
    });
});

require('test').run();